package com.jpemartin.jgt;

import java.awt.Rectangle;

public class MoveLeftRight implements MoveControl {

    protected int _speed = 4;
    protected int _dx = _speed;
    // the right edge of the game world
    protected int _maxX;
    
    /** initialize the left-right movement with the default speed (4) */
    public MoveLeftRight(int maxX) { _maxX = maxX; };
    
    /** initialize the left-right movement with the given speed */
    public MoveLeftRight(int maxX, int speed) {
      _speed = Math.abs(speed);
      _maxX = maxX;
      _dx = _speed;
    }
    
    public void move(Rectangle me) {

        if (me.x+me.width > _maxX - _speed) _dx = -_speed;
        if (me.x < _speed) _dx = _speed;

        me.x += _dx;
    }

}

